<template>
	<view style="width: 650upx;margin: 0 auto;">
		<u--form :model="form" :rules="rules" ref="uForm">
			<u-form-item prop="mobile">
				<u-input color="#ffffff" size="large" v-model="form.username" prefixIconStyle="color:#ffffff" placeholder="请输入账号"
					disableDefaultPadding prefixIcon="account-fill" style="background: rgba(255,255,255,.1);color: #fff;"
					shape="circle" />
			</u-form-item>
			<u-form-item prop="password">
				<u-input color="#ffffff" size="large" v-model="form.password" prefixIconStyle="color:#ffffff"
					placeholder="请输入密码" :type='textType' disableDefaultPadding prefixIcon="lock-fill"
					style="background: rgba(255,255,255,.1);color: #fff;" shape="circle">
					<template slot="suffix">
						<u-icon color="#ffffff" @click="lookPassword" :name="textType =='password'?'eye-fill':'eye-off'"></u-icon>
					</template>
				</u-input>
			</u-form-item>
		</u--form>
		<u-button shape="circle" size="large" color="linear-gradient(to right, rgb(66, 83, 216), rgb(213, 51, 186))"
			style="margin-top: 40upx;" @click="login">登录</u-button>
		<!-- <u-button shape="circle" size="large" color="linear-gradient(to right, rgb(0, 0, 0), rgb(0, 0, 0))" style="margin-top: 40upx;" @click="login">登录</u-button> -->
	</view>
</template>

<script>
	export default {
		data() {

			return {
				textType: 'password',
				form: {
					isMobile: 1,
					username: '',
					password: '',
				},
				rules: {
					username: [{
						required: true,
						message: '请输入账号',
						trigger: ['blur', 'change']
					}],
					password: [{
						required: true,
						message: '请输入密码',
						trigger: ['blur', 'change']
					}]
				}
			};
		},
		methods: {
			lookPassword() {
				this.textType == 'password' ? this.textType = 'text' : this.textType = 'password'
			},
			login() {
				this.$refs.uForm.validate().then(res => {
					this.https('/auth/login', this.form).then(res => {
						if (res.code == 200) {
							uni.setStorageSync('token', res.data.access_token)
							
							
							uni.setStorageSync('userId', res.data.userId)
							uni.showToast({
								title: '登录成功',
								icon: 'success'
							})
							uni.setStorageSync('password', this.form.password)
							uni.setStorageSync('userInfo', JSON.stringify(res.data.userInfo))
							uni.setStorageSync('avatar', res.data.avatar)
							setTimeout(() => {
								this.getData()
								uni.reLaunch({
									url: '/pages/home/home'
								})
							}, 2000)
						}
					})
				})
			},
			getData() {
				this.https('/client/getFunctionState', {}).then(res => {
					if (res.status == 200) {
						console.log(res.data.isOpenGpt)
						uni.setStorageSync('isOpenGpt', res.data.isOpenGpt)
					}
				})
				this.https('/client/home', {
					sendType: 1
				}).then(res => {
					if (res.status == 200) {
						uni.setStorageSync('notice', res.data.announcement)
					}
				})
			},
		}
	}
</script>

<style lang="scss">

</style>